package com.netease.financial.data.entity.mapper;

import com.netease.financial.data.entity.AccessTokenCheckEntity;
import com.netease.financial.data.entity.AppUpdateEntity;
import com.netease.financial.data.entity.LaunchPageEntity;
import com.netease.financial.data.entity.LoginEntity;
import com.netease.financial.data.entity.LogoutEntity;
import com.netease.financial.data.entity.ActivityPageEntity;
import com.netease.financial.data.entity.PageInfoEntity;
import com.netease.financial.data.entity.RegisterEntity;
import com.netease.financial.data.entity.UnreadMessageCountEntity;
import com.netease.financial.domain.model.AccessTokenCheck;
import com.netease.financial.domain.model.AppUpdate;
import com.netease.financial.domain.model.LaunchPage;
import com.netease.financial.domain.model.Login;
import com.netease.financial.domain.model.Logout;
import com.netease.financial.domain.model.ActivityPage;
import com.netease.financial.domain.model.PageInfo;
import com.netease.financial.domain.model.Register;
import com.netease.financial.domain.model.UnreadMessageCount;

import javax.inject.Inject;
import javax.inject.Singleton;

/**
 * Created by wyf on 10/12/15.
 */
@Singleton
public class NfsEntityDataMapper {

    @Inject
    public NfsEntityDataMapper() {

    }

    public AppUpdate transform(AppUpdateEntity entity) {
        AppUpdate model = new AppUpdate();
        model.setApkUrl(entity.getApkUrl());
        model.setAppName(entity.getAppName());
        model.setChangeLog(entity.getChangeLog());
        model.setForceUpdate("yes".equalsIgnoreCase(entity.getForceUpdate()));
        model.setUpdateTips(entity.getUpdateTips());
        model.setVersionCode(entity.getVersionCode());
        model.setVersionName(entity.getVersionName());
        return model;
    }

    public UnreadMessageCount transform(UnreadMessageCountEntity entity) {
        UnreadMessageCount model = new UnreadMessageCount();
        model.setCount(entity.getCount());
        return model;
    }

    public Login transform(LoginEntity entity) {
        Login model = new Login();
        model.setAccessToken(entity.getAccessToken());
        model.setAlias(entity.getAlias());
        return model;
    }

    public Logout transform(LogoutEntity entity) {
        Logout model = new Logout();
        model.setResult(entity.getResult());
        return model;
    }

    public AccessTokenCheck transform(AccessTokenCheckEntity entity) {
        AccessTokenCheck model = new AccessTokenCheck();
        model.setIsLogin(entity.isLogin());
        return model;
    }

    public ActivityPage transform(ActivityPageEntity entity) {
        ActivityPage model = new ActivityPage();
        if (entity.getActivity() != null) {
            model.setIconUrl(entity.getActivity().getIconUrl());
            model.setPageUrl(entity.getActivity().getPageUrl());
            model.setPageTitle(entity.getActivity().getPageTitle());
        }
        return model;
    }

    public LaunchPage transform(LaunchPageEntity entity) {
        LaunchPage model = new LaunchPage();
        model.setDuration(entity.getDuration());
        model.setLaunchPageImageUrl(entity.getLaunchPageImageUrl());
        model.setAgreementUrl(entity.getAgreementUrl());
        return model;
    }

    public Register transform(RegisterEntity entity) {
        Register model = new Register();
        model.setAccessToken(entity.getAccessToken());
        model.setAlias(entity.getAlias());
        return model;
    }

    public PageInfo transform(PageInfoEntity entity) {
        PageInfo model = new PageInfo();
        model.setPageName(entity.getPageName());
        model.setContent(entity.getResultContent());
        return model;
    }

}
